<?php 
include_once("round_schedule_repository.php");
include_once("match_repository.php");
include_once("team_repository.php");
$repTeam=new TeamRepository;
$repMatch=new MatchRepository;
$repSchedule= new RoundScheduleRepository;
$roundID=$_POST['roundID'];
$team1=array($_POST['team11'],$_POST['team12'],$_POST['team13'],$_POST['team14']);
$team2=array($_POST['team21'],$_POST['team22'],$_POST['team23'],$_POST['team24']);
$table=array($_POST['table1'],$_POST['table2'],$_POST['table3'],$_POST['table4']);
$type=array($_POST['final1'],$_POST['final2'],$_POST['final3'],$_POST['final4']);
for ($i=0;$i<4;$i++){
	if(($team1[$i]!=0)&&($team1[$i]!=0)){
		$repSchedule->createRoundSchedule($roundID, $team1[$i], $team2[$i], $table[$i], $type[$i]);
		$roundschedule=$repSchedule->map($repSchedule->getScheduleByRoundIDAndTeamID($roundID, $team1[$i]));
		$team1players=$repTeam->getPlayerByTeamID($team1[$i]);
		$team2players=$repTeam->getPlayerByTeamID($team2[$i]);
		$repMatch->createMatch($roundschedule->round_scheduleID, $team1players[0], $team2players[0],1);
		$repMatch->createMatch($roundschedule->round_scheduleID, $team1players[1], $team2players[1],2);
		$repMatch->createMatch($roundschedule->round_scheduleID, $team1players[2], $team2players[2],3);
		$repMatch->createMatch($roundschedule->round_scheduleID, $team1players[1], $team2players[0],4);
		$repMatch->createMatch($roundschedule->round_scheduleID, $team1players[0], $team2players[2],5);
		$repMatch->createMatch($roundschedule->round_scheduleID, $team1players[2], $team2players[1],6);
		$repMatch->createMatch($roundschedule->round_scheduleID, $team1players[1], $team2players[2],7);
		$repMatch->createMatch($roundschedule->round_scheduleID, $team1players[2], $team2players[0],8);
		$repMatch->createMatch($roundschedule->round_scheduleID, $team1players[0], $team2players[1],9);		
	}
}
		header('LOCATION:'.$_SERVER["HTTP_REFERER"]);
?>
